#!/bin/bash

echo "Building ROS2 Video Detection Camera Package..."

# 检查是否在ROS2环境中
if [ -z "$ROS_DISTRO" ]; then
    echo "Error: ROS2 environment not found. Please source ROS2 setup file first."
    echo "Example: source /opt/ros/humble/setup.bash"
    exit 1
fi

echo "ROS2 Distribution: $ROS_DISTRO"

# 创建build目录
mkdir -p build
cd build

# 运行cmake配置
echo "Configuring with CMake..."
cmake ..

# 编译
echo "Building..."
make -j$(nproc)

if [ $? -eq 0 ]; then
    echo "Build successful!"
    echo ""
    echo "To install, run:"
    echo "  cd build && make install"
    echo ""
    echo "To run the package:"
    echo "  ros2 launch video_det_camera camera_launch.py"
else
    echo "Build failed!"
    exit 1
fi
